<!DOCTYPE html>
<!--教师  添加借用实验室页面-->
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>借用实验室</title>
    <link rel="stylesheet" href="static/css/layui.css">
<!--    <link rel="stylesheet" href="static/css/style.css">-->
    <style>
        body{background-color: white}
        .layui-form-label{
            width: 100px;
        }
        .layui-input-block {
            margin-left: 130px;
            min-height: 36px
        }
    </style>
    <script src="static/js/jquery-2.1.3.min.js"></script>
</head>
<body class="body">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>借用实验室</legend>
</fieldset>

<form class="layui-form layui-from-pane" style="margin-top:20px" method="post">

        <div class="w3_agileits_main_grid w3l_main_grid">
            <span class="agileits_grid">
                <label  style="margin-left: 43px;margin-right: 10px">可用实验室<i>:</i></label>
                <div class="layui-input-inline">
                   <select name="sysid" id="sysid"></select>
                </div>
            </span>
        </div>
    <br>

    <div class="layui-form-item">
        <label class="layui-form-label">上传文件：</label>
        <div class="layui-input-block">
<!--            <input type="text" name="info"  autocomplete="off" placeholder="" class="layui-input" style="width: 90%">-->
            <input name="img" id="img" placeholder="请上传文件待管理员审批" class="layui-input" style="width: 90%" required>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>上传文件
            </button></br></br>
        </div>
    </div>


    <div class="layui-form-item" style="margin-top:40px">
        <div class="layui-input-block">
            <button class="layui-btn  layui-btn-submit " lay-submit="" lay-filter="demo1">添加</button>
        </div>
    </div>
</form>
<script src="static/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','layer','jquery','upload'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,upload = layui.upload
            ,$=layui.jquery
        $.ajax({
            url:"/selectkysys",
            type:"post",
            dataType:"json",
            success: function (result) {
                var optionstring = "";
                for (var j = 0; j < result.count; j++) {
                    optionstring += "<option value='" + result.data[j].id + "'>" + result.data[j].sysname+"---"+result.data[j].bh + "</option>";
                }
                $("#sysid").html(optionstring);
                form.render('select');
            },
            error:function (e) {
                layer.msg('服务器错误',{icon:2});
            }
        });
        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/layupload' //上传接口
            ,exts: 'txt|doc|docx|zip|rar|ppt|pptx|pdf'
            ,before: function(obj){
                layer.msg('文件上传中...', {
                    icon: 16,
                    shade: 0.01,
                    time: 0
                })
            }
            ,done: function(res){
                //上传完毕回调
                console.log(res);
                // $('#photopath').val("images/upload/"+res.filenamed);
                $('#img').val("upload/"+res.filenamed);
                layer.close(layer.msg());
                layer.msg('文件上传成功！',{icon:1});
            }
            ,error: function(){
                layer.msg('文件上传失败！',{icon:2});
                //请求异常回调
            }
        });
        //监听提交
        form.on('submit(demo1)', function(data){
            var sysid = $('#sysid').val();
            var img = $('#img').val();
            $.ajax({

                url:'/Insertjysysgl',
                type:'POST',
                dataType:'json',
                data:{
                    sysid:sysid,
                    img:img
                },
                success:function (msg) {
                    if(msg){
                        layer.closeAll('loading');
                        layer.load(2);
                        layer.msg("添加成功", {icon: 1});
                        setTimeout(function(){
                            window.parent.location.reload();//修改成功后刷新父界面
                        }, 1000);
                        //加载层-风格

                    }else{
                        layer.msg("添加失败", {icon: 2});
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>